package com.dm0858.bianmin.mine.tools;

/**
 * @description 单位转换工具类
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-03-17
 **/
public class ConversionUtils {

    public ConversionUtils() {
        throw new UnsupportedOperationException("u can't instantiate me");
    }

    /**
     * @description px 转 dp
     * @param
     * @return
     * @author 迪迪丶Sir
     * @since 2020-03-17
     **/
    public static int px2dp(float pxValue) {
        final float scale = ScreenUtils.getScreenDensity();
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * @description dp 转 px
     * @param
     * @return
     * @author 迪迪丶Sir
     * @since 2020-03-17
     **/
    public static int dp2px(float dpValue) {
        final float scale = ScreenUtils.getScreenDensity();
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * @description px 转 sp
     * @param
     * @return
     * @author 迪迪丶Sir
     * @since 2020-03-17
     **/
    public static int px2sp(float pxValue) {
        final float fontScale = ScreenUtils.getScreenScaleDensity();
        return (int) (pxValue / fontScale + 0.5f);
    }

    public static int sp2px(float spValue) {
        final float fontScale = ScreenUtils.getScreenScaleDensity();
        return (int) (spValue * fontScale + 0.5f);
    }
}
